/*
 * Copyright © 2020-present zmzhou-star. All Rights Reserved.
 */

package com.handa.webShell.config;

import com.handa.webShell.websocket.handle.WebSFTPHandler;
import com.handa.webShell.websocket.handle.WebSSHHandler;
import com.handa.webShell.websocket.interceptor.WebSocketInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;

/**
 * websocket配置
 */
@Configuration
@EnableWebSocket
public class WebShellWebSocketConfig implements WebSocketConfigurer {
	@Resource
	private WebSSHHandler webSSHHandler;

    @Resource
    private WebSFTPHandler webSFTPHandler;

	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
		//socket通道
		//指定处理器和路径
		webSocketHandlerRegistry.addHandler(webSSHHandler, "/WebShell/socket/webShell-connect")
				.addInterceptors(new WebSocketInterceptor())
				.setAllowedOrigins("*");

        webSocketHandlerRegistry.addHandler(webSFTPHandler, "/WebShell/socket/webSFTP-connect")
                .addInterceptors(new WebSocketInterceptor())
                .setAllowedOrigins("*");
	}
}
